package com.jojo.bubble.controller.api;

import com.jojo.bubble.common.domain.AjaxResult;
import com.jojo.bubble.entity.User;
import com.jojo.bubble.service.UserService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author JoJo
 * @Date 2023/7/27 18:03
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/user")
public class UserApiController {
    @Resource
    UserService userService;

    @GetMapping("/info")
    public AjaxResult getInfo(Integer id) {
//        System.out.println("info:"+id);
        User user = userService.getInfo(id);
        return AjaxResult.success(user);
    }

    @GetMapping("/queryOpenId")
    public AjaxResult queryByOpenId(User user) {
        User user1 = userService.queryByOpenId(user.getOpenId());
        if (ObjectUtils.isEmpty(user1)) {
            return AjaxResult.error("openId error");
        }
        return AjaxResult.success(user1);
    }

    @GetMapping("/list")
    public AjaxResult getInfo(User record) {
        List<User> userList = userService.getList(record);
        return AjaxResult.success(userList);
    }

}
